package br.com.cardapiolivre.persistencia;

import java.util.List;
import javax.persistence.Query;
import br.com.cardapiolivre.entidades.Teste;

public class TesteDaoJpa extends DaoJpa<Teste> {

    public Teste consultar(Long id) throws Exception {
        try {
            return (Teste) em.find(Teste.class, id);
        } catch (Exception ex) {
            throw ex;
        }
    }

    public List<Teste> consultar() throws Exception {
        try {
            Query q = em.createQuery("SELECT t FROM Teste t ");
            return q.getResultList();
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new Exception("Erro ao consultar.");
        }
    }

    public List<Teste> consultarNome(String teste) throws Exception {
        try {
            Query q = em.createQuery("SELECT t FROM Teste t WHERE t.teste LIKE '" + teste + "%'");
            return q.getResultList();
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new Exception("Erro ao consultar.");
        }
    }

    public List<Teste> consultarPreco(float preco) {

        return null;
    }
}
